import { Tooltip } from 'antd';
import { getTenantID } from '@/utils';
import { ILoadMapTypeAll } from '@/common';
import pageStyles from '@/common/pageLayout.less';

/** 流程相关&流程类别【category】*/
export const flowBusinessType = () => {
  return `${getTenantID()}${ILoadMapTypeAll.ALLFLOW_TYPE}1001`;
};

/**判断值是否有两位小数点，没有则自动补零*/
export const formatDecimal = (val: any) => {
  // 不存在的话就返回'--'
  if (!val) return '--';
  // 将输入值转为数字，以确保处理的是数值类型
  const num = Number(val);
  // 如果转换后的数值是NaN，则直接返回原始值
  if (isNaN(num)) return '--';
  // 使用toFixed方法确保小数点后有两位，然后再转回字符串
  return num.toFixed(2) + '';
};

/***
 * 需求申请管理 -- <审核状态>
 * @param state
 * */
export const requirementApplicationFormat = (state: number | null | undefined) => {
  if (typeof state !== 'number') return '--';

  if (state == 1) {
    return <span style={{ color: '#0c880c' }}>通过</span>;
  } else if (state == 2) {
    return <span style={{ color: '#fcc128' }}>驳回</span>;
  } else if (state == 3) {
    return <span style={{ color: '#fcc128' }}>暂缓</span>;
  } else {
    return <span style={{ color: '#e17ec7' }}>取消</span>;
  }
};

/***
 * 物料管理 -- <签发方式> -- 处理
 * @param state
 * */
export const signTypeOfRendering = (state: number | null | undefined) => {
  if (typeof state !== 'number') return '--';
  if (state == 0)
    return (
      <div>
        <span style={{ color: '#ad69f5' }}>直接签发</span>
      </div>
    );
  else
    return (
      <div>
        <span style={{ color: '#f49609' }}>审核签发</span>
      </div>
    );
};

/**
 * @renderOverflowText
 * @description 处理文字溢出
 * @param text 值
 * @param isShowTooltip 是否溢出隐藏并且加Tooltip
 * @returns
 */
export const renderOverflowText = (text: string | number | null, isShowTooltip = false) => {
  const index = ['0', '1'].indexOf(String(text) || '');
  // 干掉字典颜色
  // const { colorText, color } = getColorTextLoadMap(String(text));
  // const info = {
  //     word: colorText == 'undefined' || colorText == 'null' || !colorText ? '--' : colorText,
  //     color: color,
  // };
  const info = {
    word: text ?? '--',
    color: '',
  };

  if (index != -1) {
    info.word = index == 1 ? '是' : '否';
    info.color = index == 1 ? '#409eff' : 'red';
  }
  if (isShowTooltip && info.word != '--') {
    return (
      <Tooltip title={info.word}>
        <span className={pageStyles['over-flow-hidden']} style={{ color: info.color }}>
          {info.word}
        </span>
      </Tooltip>
    );
  } else {
    return <span style={{ color: info.color }}>{info.word}</span>;
  }
};

/***
 * 寻源意向公开 state 翻译
 * @param state
 * */
export const translationState = (state: any) => {
  if (typeof state !== 'number') return '--';
  if (state == 0)
    return (
      <div>
        <span style={{ color: '#4246d1' }}>起草</span>
      </div>
    );
  else if (state == 1)
    return (
      <div>
        <span style={{ color: '#1e9392' }}>审核中</span>
      </div>
    );
  else if (state == 2)
    return (
      <div>
        <span style={{ color: '#9d3df0' }}>已通过</span>
      </div>
    );
  else if (state == 3)
    return (
      <div>
        <span style={{ color: '#57ab91' }}>未通过</span>
      </div>
    );
  else
    return (
      <div>
        <span style={{ color: '#5c6f91' }}>已作废</span>
      </div>
    );
};

/***
 * 寻源意向公开 checkState 翻译
 * @param state
 * */
export const translationCheckState = (state: any) => {
  if (typeof state !== 'number') return '--';
  if (state == 0)
    return (
      <div>
        <span style={{ color: '#4246d1' }}>待审核</span>
      </div>
    );
  else if (state == 1)
    return (
      <div>
        <span style={{ color: '#1e9392' }}>通过</span>
      </div>
    );
  else if (state == 2)
    return (
      <div>
        <span style={{ color: '#9d3df0' }}>驳回</span>
      </div>
    );
  else
    return (
      <div>
        <span style={{ color: '#5c6f91' }}>作废</span>
      </div>
    );
};
